﻿package mortal.game.view.copy.GroupTowerCopy.panel
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GroupTowerFaildWin extends Window
    {
        protected var _bg:GImageBitmap;
        protected var _rwBg:ScaleBitmap;
        protected var _enterBtn:GLoadingButton;
        protected var _tip:GImageBitmap;
        protected var _title:GImageBitmap;
        protected var _guan:BitmapNumberText;
        protected var _rwList:CellsGridSprite;
        protected var _resultIcon:GImageBitmap;
        protected var _guanTitle:BitmapNumberText;
        protected var _passTitle:GImageBitmap;
        protected var _guanDes:GImageBitmap;
        protected var _totalGuan:BitmapNumberText;
        protected var _guanTip:BitmapNumberText;
        protected var _pageSelector:PageSelecter;
        private var _secTimer:SecTimer;
        private var _timeOutNum:int = 20;
        private var _pageTool:PageTool;
        private var _GiftLen:int = 4;
        private static var _instance:GroupTowerFaildWin;

        public function GroupTowerFaildWin(param1:ILayer = null)
        {
            super(param1);
            setSize(696, 357);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipBg, 0, -56, this);
            this._rwBg = UIFactory.bg(191, 86, 384, 118, this, ImagesConst.PanelBg);
            this._enterBtn = UIFactory.gLoadingButton(ImagesConst.ResultWindowBtn_upSkin, 330, 253, 114, 33, this);
            this._enterBtn.label = "";
            this._tip = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTip, 214, 227, this);
            this._title = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTitle, 179, 36, this);
            this._guan = UIFactory.bitmapNumberText(336, 46, "BasePassWinNum.png", 18, 21, -8, this, 12, 1);
            this._guan.text = "18";
            this._rwList = UIFactory.getUICompoment(CellsGridSprite);
            this._rwList.colNum = 4;
            this._rwList.vCellWid = 75;
            this._rwList.hCellWid = 100;
            this._rwList.genCellFun = this.genCells;
            this._rwList.genCells(4);
            this._rwList.x = 235;
            this._rwList.y = 96;
            this.addChild(this._rwList);
            this._resultIcon = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipTitle, 112, -37, this);
            this._guanTitle = UIFactory.bitmapNumberText(425, -9, "SignUpNum2.png", 22, 29, -6, this, 13, 1);
            this._guanTitle.text = "90";
            this._passTitle = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipTitlePass, 113, -39, this);
            this._guanDes = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailGuanDes, 306, 203, this);
            this._totalGuan = UIFactory.bitmapNumberText(376, 203, "BasePassWinNum.png", 18, 21, -8, this, 12, 1);
            this._totalGuan.text = "20";
            this._guanTip = UIFactory.bitmapNumberText(415, 204, "DefensePass2Num.png", 12, 22, 0, this, 14, 0);
            this._guanTip.text = "(10/120)";
            this._pageSelector = UIFactory.pageSelecter(346, 174, this, PageSelecter.SingleMode);
            this._pageSelector.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelector.maxPage = 1;
            this._pageSelector.pageTextBoxSize = 36;
            this._pageSelector.configEventListener(Event.CHANGE, this.onPageChange);
            this._totalGuan.text = "" + GroupTowerCopyUtil.TotalLevel;
            this._pageTool = new PageTool([], this._GiftLen);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onCkHd);
            this._secTimer = new SecTimer(1);
            this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            this._secTimer.repeatCount = this._timeOutNum;
            this._secTimer.start();
            return;
        }// end function

        private function genCells() : BaseItem
        {
            var _loc_1:* = UIFactory.getUICompoment(BaseItem);
            _loc_1.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._rwBg = null;
            this._enterBtn = null;
            this._tip = null;
            this._title = null;
            this._guan = null;
            this._rwList = null;
            this._resultIcon = null;
            this._guanTitle = null;
            this._passTitle = null;
            this._guanDes = null;
            this._totalGuan = null;
            this._guanTip = null;
            this._pageSelector = null;
            this._pageTool = null;
            this._secTimer = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            var _loc_4:BaseItem = null;
            var _loc_5:ItemData = null;
            var _loc_2:* = this._pageTool.getByPageNo(this._pageSelector.currentPage);
            this._rwList.genCells(this._GiftLen);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length && _loc_3 < this._rwList.cellArr.length)
            {
                
                _loc_4 = this._rwList.cellArr[_loc_3];
                _loc_5 = _loc_2[_loc_3];
                _loc_4.itemData = _loc_5;
                _loc_3++;
            }
            return;
        }// end function

        private function onCkHd(event:MouseEvent) : void
        {
            this.onTimerCompleteHandler(null);
            return;
        }// end function

        private function onTimerCompleteHandler(param1:SecTimer) : void
        {
            this._secTimer.stop();
            this.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave));
            return;
        }// end function

        public function updateFailInfo(param1:Array, param2:int = -1) : void
        {
            if (param1 == null || param1.length < 2)
            {
                return;
            }
            var _loc_3:* = param1[0];
            var _loc_4:* = param1[1];
            var _loc_5:* = _loc_3[0];
            var _loc_6:* = _loc_3[1];
            _loc_5 = _loc_5 < 0 ? (0) : (_loc_5);
            var _loc_7:* = "" + _loc_5;
            this._guan.text = "" + _loc_5;
            this._guanTitle.text = _loc_7;
            this._guanTip.text = "(" + _loc_5 + "/" + _loc_6 + ")";
            this._totalGuan.text = "" + _loc_6;
            if (_loc_6 == _loc_5 && EDefenseCopyResult._EDefenseCopySuccess == param2)
            {
                this._passTitle.visible = true;
                var _loc_7:Boolean = false;
                this._guanTitle.visible = false;
                this._resultIcon.visible = _loc_7;
            }
            else
            {
                this._passTitle.visible = false;
                var _loc_7:Boolean = true;
                this._guanTitle.visible = true;
                this._resultIcon.visible = _loc_7;
            }
            this.updateRw(_loc_4);
            return;
        }// end function

        private function updateRw(param1:Array) : void
        {
            if (param1)
            {
                this._pageTool.array = param1;
                this._pageSelector.maxPage = Math.ceil(param1.length / this._GiftLen);
                this.onPageChange(null);
            }
            return;
        }// end function

        public static function get instance() : GroupTowerFaildWin
        {
            if (_instance == null)
            {
                _instance = new GroupTowerFaildWin;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
